package com.hl.security;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.web.authentication.SavedRequestAwareAuthenticationSuccessHandler;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * Created by evan on 2016/2/24.
 */
public class UserAuthenticationSuccessHandler extends
        SavedRequestAwareAuthenticationSuccessHandler {

    @Resource(name = "redisTemplate")
    private ValueOperations<String, Object> jedis;

    private static final Logger LOGGER = LoggerFactory.getLogger(UserAuthenticationSuccessHandler.class);

    @Override
    public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) {
        try {
            //login sucess page
            String sucessPageStr = request.getParameter("login_success_page");
            response.sendRedirect(sucessPageStr);
            UserDetail userDetail=(UserDetail) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
           // jedis.set("userDetail",userDetail);
        } catch (IOException e) {
            e.printStackTrace();
        }


    }

}

